<template>
  <div class="app-container">

    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input
        v-model="listQuery.username"
        clearable
        size="mini"
        class="filter-item"
        style="width: 200px;"
        placeholder="用户名"
      />
      <el-input
        v-model="listQuery.mobile"
        clearable
        size="mini"
        class="filter-item"
        style="width: 200px;"
        placeholder="请输入手机号"
      />
      <el-input
        v-model="listQuery.region"
        clearable
        size="mini"
        class="filter-item"
        style="width: 200px;"
        placeholder="区域"
      />
      <el-input
        v-model="listQuery.address"
        clearable
        size="mini"
        class="filter-item"
        style="width: 200px;"
        placeholder="请输入地址"
      />
      <el-button
        size="mini"
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >查找
      </el-button>
    </div>

    <!-- 查询结果 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      size="small"
      element-loading-text="正在查询中。。。"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        align="center"
        min-width="110"
        label="用户名"
        prop="userName"
      />
      <el-table-column
        align="center"
        min-width="110"
        label="性别"
        prop="userSex"
      >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.userSex === 'male'" size="medium">男</el-tag>
          <el-tag v-else size="medium">女</el-tag>
          <el-tag v-else size="medium">未知</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        min-width="200"
        label="手机号码"
        prop="userMobile"
      />

      <el-table-column
        align="center"
        property="userRegion"
        label="意向加盟区域"
      >
      </el-table-column>

      <el-table-column
        align="center"
        label="用户地址"
        prop="userAddress"
      />

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />

    <el-tooltip
      placement="top"
      content="返回顶部"
    >
      <back-to-top :visibility-height="100"/>
    </el-tooltip>

  </div>
</template>

<script>
import BackToTop from '@/components/BackToTop'
import Pagination from '@/components/Pagination'
import { getToken } from '@/utils/auth'
import {
  listUserApply
} from "@/api/business/userApply"

export default {
  name: 'userApply',
  components: { BackToTop, Pagination },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        username: '',
        mobile: '',
        address: '',
        region: '',
      },
    }
  },
  computed: {
    headers() {
      return {
        'X-Dts-Merchant-Token': getToken()
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    getList() {
      this.listLoading = true
      listUserApply(this.listQuery).then(response => {
        this.list = response.data.data.items
        this.total = response.data.data.total
        this.listLoading = false
      }).catch(() => {
        this.list = []
        this.total = 0
        this.listLoading = false
      })
    },
  }
}
</script>

<style>

.table-expand {
  font-size: 0;
}

.table-expand label {
  width: 100px;
  color: #99a9bf;
}

.table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
}

.gallery {
  width: 80px;
  margin-right: 10px;
}

.htmlSpan {
  white-space: pre-wrap;
  word-break: break-all;
}
</style>
